﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using HNQXYJ.Model;
using HNQXYJ.BLL;
using HNQXYJ.DAL;

namespace HNQXYJ
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
           //StartListen();
            int i = 0;
            //System.Timers.Timer aTimer = new System.Timers.Timer();
            //aTimer.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
            //aTimer.Interval = 1000*60*60;//一小时执行一次
            //aTimer.Enabled = true;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
           
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            
        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
           
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }

        void aTimer_Elapsed(object sender,System.Timers.ElapsedEventArgs e)
        {
            //int intMinute = e.SignalTime.Minute;
            //int intHour = e.SignalTime.Hour;
            //EquipOnlineBLL eob = new EquipOnlineBLL();
            //EquipOnline eo = new EquipOnline();
            //List<Terminal> list = TerminalBLL.GetPhoneAndStatus();
            //string flage ;
            //foreach ( Terminal tm in list)
            //{
            //    eo.Phone = tm.Phone;
            //    eo.DateAdd = DateTime.Now.ToString("yyyy-MM-dd");

            //        if (tm.Statuss == "离线")
            //        {
            //            flage = "0";
            //        }
            //        else
            //        {
            //            flage = "1";
            //        }
            //        if (intHour == 00 && intMinute==50)
            //        {
            //            int res = eob.AddDataOnTime00(eo, flage);
            //        }
            //        if(intHour !=00 && intMinute==50)
            //        {
            //            int count = eob.IsHavePhoneAndDateAdd(eo);
            //            if (count < 1)//非零点的时候更新数据表时先检查是不是存在该条数据 不存在就先插入             
            //            {
            //                int res = eob.AddDataOnTime00(eo, "0");
            //                if (flage == "1")//插入数据后立即判断该终端是否在线，若在线则立即更新
            //                {
            //                    eob.UpdateOnHour(eo, intHour);
            //                }
            //            }
            //            else
            //            {   //若 存在该日期下对应的数据 则判断状态 在线就更新 不在线则保持默认值
            //                 if (flage == "1")//终端在线时更新状态表
            //                 {
            //                     eob.UpdateOnHour(eo, intHour);
            //                 }
            //            }    
            //        }
            //}
           
        }

        void StartListen(){
        //{
        //    SysConfig sc = new SysConfig();
        //    SysConfigBLL scb = new SysConfigBLL();
        //    sc = scb.ReturnSysConfig();
        //    if (sc != null)
        //    {
        //        string ip = sc.Ip;
        //        int port = sc.Port;
        //        SocketListen.StartListen(ip, port);//192.168.70.111

        //    }
        }
    }
}